package com.ssy.lingxi.order.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Set;

/**
 * 交易流程规则配置
 *
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-23
 */
@Entity
@Table(schema = "public", name = "ord_trade_process", indexes = {@Index(name = "ord_trade_process_member_id_idx", columnList = "memberId"), @Index(name = "ord_trade_process_role_id_idx", columnList = "roleId"), @Index(name = "ord_trade_process_name_idx", columnList = "name"), @Index(name = "ord_trade_process_create_time_idx", columnList = "createTime"), @Index(name = "ord_trade_process_shop_id_idx", columnList = "shopId"), @Index(name = "ord_trade_process_shop_type_idx", columnList = "shopType"), @Index(name = "ord_trade_process_process_type_idx", columnList = "processType"), @Index(name = "ord_trade_process_status_idx", columnList = "status"), @Index(name = "ord_trade_process_all_products_idx", columnList = "allProducts")})
public class OrderTradeProcessDO implements Serializable {
    private static final long serialVersionUID = 509660445577071473L;

    /**
     * 主键Id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ord_trade_process_seq")
    @SequenceGenerator(sequenceName = "ord_trade_process_seq", name = "ord_trade_process_seq", allocationSize = 1)
    private Long id;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime createTime;

    /**
     * 会员Id
     */
    @Column
    private Long memberId;

    /**
     * 会员角色Id
     */
    @Column
    private Long roleId;

    /**
     * 规则名称
     */
    @Column(columnDefinition = "varchar(50)")
    private String name;

    /**
     * 商城Id
     */
    @Column
    private Long shopId;

    /**
     * 商城类型，定义在 ShopTypeEnum 中
     */
    @Column
    private Integer shopType;

    /**
     * 商城环境，定义在 ShopEnvironmentEnum 中
     */
    @Column
    private Integer shopEnvironment;

    /**
     * 流程类型，定义在 OrderTradeProcessTypeEnum 中
     */
    @Column
    private Integer processType;

    /**
     * 流程类别，定义在 WorkflowProcessKindEnum 中， 1-内部流程，2-外部流程，3-复杂流程
     */
    @Column
    private Integer processKind;

    /**
     * 流程中的支付次数
     */
    @Column
    private Integer payTimes;

    /**
     * 流程启动时是否需要执行第一步
     */
    @Column
    private Boolean skipFirstStep;

    /**
     * 流程的Key
     */
    @Column(columnDefinition = "varchar(100)")
    private String processKey;

    /**
     * 订单自动取消时间（小时）
     */
    @Column(columnDefinition = "numeric")
    private BigDecimal expireHours;

    /**
     * 是否使用电子合同
     */
    @Column
    private Boolean hasContract;

    /**
     * 是否包含所有商品
     */
    @Column
    private Boolean allProducts;

    /**
     * 状态，0-停用，1-启用
     */
    @Column
    private Integer status;

    /**
     * 多对一单向关联基础交易流程
     */
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "base_trade_process_id")
    private BaseTradeProcessDO baseTradeProcess;

    /**
     * 一对一双向关联电子合同
     */
    @JsonManagedReference
    @OneToOne(cascade = {CascadeType.DETACH, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    @JoinColumn(name="process_contract_id", referencedColumnName="id")
    private OrderTradeProcessContractDO contract;

    /**
     * 一对多双向关联支付环节设置
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "process", cascade = {CascadeType.DETACH, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    private Set<OrderTradeProcessPaymentDO> payments;

    /**
     * 一对多双向关联流程规则配置的商品
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "process", cascade = {CascadeType.DETACH, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    private Set<OrderTradeProcessProductDO> products;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getShopId() {
        return shopId;
    }

    public void setShopId(Long shopId) {
        this.shopId = shopId;
    }

    public Integer getShopType() {
        return shopType;
    }

    public void setShopType(Integer shopType) {
        this.shopType = shopType;
    }

    public Integer getShopEnvironment() {
        return shopEnvironment;
    }

    public void setShopEnvironment(Integer shopEnvironment) {
        this.shopEnvironment = shopEnvironment;
    }

    public Integer getProcessType() {
        return processType;
    }

    public void setProcessType(Integer processType) {
        this.processType = processType;
    }

    public Integer getProcessKind() {
        return processKind;
    }

    public void setProcessKind(Integer processKind) {
        this.processKind = processKind;
    }

    public Integer getPayTimes() {
        return payTimes;
    }

    public void setPayTimes(Integer payTimes) {
        this.payTimes = payTimes;
    }

    public Boolean getSkipFirstStep() {
        return skipFirstStep;
    }

    public void setSkipFirstStep(Boolean skipFirstStep) {
        this.skipFirstStep = skipFirstStep;
    }

    public String getProcessKey() {
        return processKey;
    }

    public void setProcessKey(String processKey) {
        this.processKey = processKey;
    }

    public BigDecimal getExpireHours() {
        return expireHours;
    }

    public void setExpireHours(BigDecimal expireHours) {
        this.expireHours = expireHours;
    }

    public Boolean getHasContract() {
        return hasContract;
    }

    public void setHasContract(Boolean hasContract) {
        this.hasContract = hasContract;
    }

    public Boolean getAllProducts() {
        return allProducts;
    }

    public void setAllProducts(Boolean allProducts) {
        this.allProducts = allProducts;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public BaseTradeProcessDO getBaseTradeProcess() {
        return baseTradeProcess;
    }

    public void setBaseTradeProcess(BaseTradeProcessDO baseTradeProcess) {
        this.baseTradeProcess = baseTradeProcess;
    }

    public OrderTradeProcessContractDO getContract() {
        return contract;
    }

    public void setContract(OrderTradeProcessContractDO contract) {
        this.contract = contract;
    }

    public Set<OrderTradeProcessPaymentDO> getPayments() {
        return payments;
    }

    public void setPayments(Set<OrderTradeProcessPaymentDO> payments) {
        this.payments = payments;
    }

    public Set<OrderTradeProcessProductDO> getProducts() {
        return products;
    }

    public void setProducts(Set<OrderTradeProcessProductDO> products) {
        this.products = products;
    }
}
